package _2025_3_12;

class MyRunnable implements Runnable {
    private int index;

    public MyRunnable(int index) {
        this.index = index;
    }

    public void run() {
        System.out.println("Thread " + index + " is running.");
    }
}

public class Main {
    public static void main(String[] args) {
        Thread[] threads = new Thread[20];

        // 创建并启动20个线程
        for (int i = 0; i < 20; i++) {
            threads[i] = new Thread(new MyRunnable(i));
            threads[i].start();
        }

        // 等待所有线程执行完毕
        for (int i = 0; i < 20; i++) {
            try {
                threads[i].join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        // 所有线程执行完毕后打印 ok
        System.out.println("ok");
    }
}